import { MergeConfigType, MergeConfigItem } from '@/components/FormPro/props';
import { getEditOrDetailConfig } from '@/components/FormPro/util';
import SelectSpaceDriver from '@/components/SelectSpaceDriver/index.vue';
import SelectSpaceCar from '@/components/SelectSpaceCar/index.vue';

export const getFormFileds = (type: MergeConfigType) => {
  const formBaseList: MergeConfigItem[] = [
    {
      label: '车辆',
      filed: 'car_id',
      props: {
        col: {
          span: 24,
        },
      },
      edit: {
        props: {
          component({ formModel }) {
            return {
              placeholder: '车辆',
              params: {
                id: formModel.id,
                order_id: formModel.orderId,
              },
            };
          },
          formItem: {
            rules: [
              { required: true, trigger: 'change', message: '请选择 车辆' },
            ],
          },
        },
        events: {
          change({ componentVal, formModel }) {
            formModel.driver_id = componentVal?.[1]?.driver_id || '';
          },
        },
        component: SelectSpaceCar,
      },
    },
    {
      label: '驾驶员',
      filed: 'driver_id',
      props: {
        col: {
          span: 24,
        },
      },
      edit: {
        props: {
          component({ formModel }) {
            return {
              placeholder: '请选择 驾驶员',
              params: {
                id: formModel.id,
                order_id: formModel.orderId,
              },
            };
          },
          formItem: {
            rules: [
              { required: true, trigger: 'change', message: '请选择 驾驶员' },
            ],
          },
        },
        component: SelectSpaceDriver,
      },
    },
  ];

  return getEditOrDetailConfig(formBaseList, type);
};
